//
//  MHSettingPublishPermissionViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/20.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHSettingPublishPermissionViewController.h"
#import "MHSettingPublishPermissionViewModel.h"
#import "MHCommonCell.h"



@interface MHSettingPublishPermissionViewController ()
@property(nonatomic, strong)  MHSettingPublishPermissionViewModel *viewModel;
@property(nonatomic, assign) NSIndexPath *indexPath;
@end

@implementation MHSettingPublishPermissionViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    self.indexPath = [NSIndexPath indexPathForRow:0 inSection:self.viewModel.info.publishAuth - 1 ];
    self.view.userInteractionEnabled  =  [self.viewModel.info currentUserIsOwner];
    
    if (![self.viewModel.info currentUserIsOwner]) {
        self.navigationItem.titleView = createAttriNavTitleLable(@"设置发表权限", @"仅圈主可设置");
    }
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object
{
    MHCommonItemViewModel *model = (MHCommonItemViewModel *)object;
    if (indexPath == self.indexPath) {

        model.isSelected = true;
    }else
    {
        model.isSelected = false;
    }
    [cell bindViewModel:object];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    // execute commond
    [self.viewModel.didSelectCommand execute:indexPath];
//    id object = nil;
    self.indexPath = indexPath;

//    MHCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
//    MHCommonItemViewModel *object = groupViewModel.itemViewModels[indexPath.row];
    self.viewModel.info.publishAuth = (int)indexPath.section  + 1;
//    object.isSelected =  [self.viewModel.info.publishAuth  isEqualToString: [NSString stringWithFormat:@"%ld",indexPath.row + 1]];
    [self.tableView reloadData];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
